﻿using Longbow.Web;
using System;

namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// IP地理位置扩展操作类
    /// </summary>
    public static class IPLocatorServicesCollectionExtensions
    {
        /// <summary>
        /// IP地理位置定位器配置回调委托
        /// </summary>
        private static Action<IPLocatorOption> _configure;

        /// <summary>
        /// 添加IP定位服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configure">定位器配置选项</param>
        /// <returns></returns>
        public static IServiceCollection AddIPLocator(this IServiceCollection services, Action<IPLocatorOption> configure = null)
        {
            _configure = configure;
            services.AddSingleton<IIPLocatorProvider, DefaultIPLocatorProvider>();
            return services;
        }

        /// <summary>
        /// IPLocatorOption 配置回调方法
        /// </summary>
        /// <returns></returns>
        internal static void ConfigureOption(IPLocatorOption option) => _configure?.Invoke(option);
    }
}
